package com.stx.category.service.impl;

import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.BeanUtils;

import com.stx.blog.entity.BlogEntity;
import com.stx.blog.vo.BlogVO;
import com.stx.category.dao.CategoryDAO;
import com.stx.category.entity.CategoryEntity;
import com.stx.category.service.CategoryService;
import com.stx.category.vo.CategoryVO;
import com.stx.user.entity.UserEntity;
import com.stx.user.vo.UserVO;

public class CategoryServiceImpl implements CategoryService {
	CategoryDAO categorydao;

	public CategoryDAO getCategorydao() {
		return categorydao;
	}

	public void setCategorydao(CategoryDAO categorydao) {
		this.categorydao = categorydao;
	}

	@Override
	public List<CategoryVO> listCategory() {

		List<CategoryVO> voList = new ArrayList<CategoryVO>();

		List<CategoryEntity> entityList = categorydao.listCategory();

		for (CategoryEntity entity : entityList) {

			CategoryVO vo = new CategoryVO();

			// 对象属性值拷贝 entity => vo
			BeanUtils.copyProperties(entity, vo);

			voList.add(vo);

		}

		return voList;

	}

	@Override
	public CategoryVO getCategoryByCid(String cID) {
		CategoryVO categoryvo = new CategoryVO();
		CategoryEntity categoryEntity = categorydao.getCategoryByCid(cID);
		BeanUtils.copyProperties(categoryEntity, categoryvo);
		return categoryvo;
	}

	@Override
	public List<CategoryVO> getCategoryByUserID(String userID) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void addCategory(CategoryVO categoryvo) {
		categorydao.addCategory(categoryvo);
	}

	@Override
	public void deleteCategory(String cID) {
		categorydao.deleteCategory(cID);
	}

	@Override
	public void editCategory(String cID, String cName) {
		categorydao.editCategory(cID, cName);
	}

	@Override
	public List<BlogVO> listBlogBycategoryID(String cid) {

		List<BlogVO> blogList = new ArrayList<BlogVO>();
		List<BlogEntity> entityList = categorydao.listBlogBycategoryID(cid);

		for (BlogEntity entity : entityList) {

			BlogVO vo = new BlogVO();

			// 对象属性值拷贝 entity => vo
			BeanUtils.copyProperties(entity, vo);

			blogList.add(vo);

		}

		return blogList;
	}

}
